package roborally.script.singleCondition;

import roborally.model.Element;
import roborally.model.Item;
import roborally.model.Robot;
import roborally.script.SingleCondition;
import be.kuleuven.cs.som.annotate.*;
import be.kuleuven.cs.som.taglet.*;

/**
 * @author Joren VERSPEURT
 * @author Mathieu REYMOND
 * @version 3.0
 * 
 * The class representing an AtItem statement in the RoboRally script language.
 */
public class AtItem extends SingleCondition {

	/**
	 * Create a new AtItem condition with a given Robot.
	 * @param robot The Robot this AtItem condition will apply to.
	 */
	public AtItem(Robot robot) {
		super(robot);
	}

	/**
	 * This Condition is true when <code>robot</code> shares its position with an item.
	 */
	@Override
	public boolean isTrue() {
		boolean result = false;
		for(Element element : robot.getBoard().getElements(robot.getPosition())) {
			if(element.getClass().isAssignableFrom(Item.class)) {
				result = true;
				break;
			}
		}
		return result;
	}
	
	/**
	 * The script word for this condition.
	 */
	@Override
	public String toString(){
		return "at-item";
	}
}
